package com.xhwl.logistics.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@AllArgsConstructor
@Getter
public enum VehiclePassageTypeEnum {

    ENTRANCE(0, "入口"),
    EXIT(1, "出口"),
    MIDDLE_ENTRANCE(2, "中间入口"),
    MIDDLE_EXIT(3, "中间出口"),
    PASSAGE_TYPE_NOTHING(99, "Nothing_Passage_Type");

    private static final Map<Integer, VehiclePassageTypeEnum> map;
    static {
        map = new HashMap<>();
        for (VehiclePassageTypeEnum vehiclePassageTypeEnum : VehiclePassageTypeEnum.values()) {
            map.put(vehiclePassageTypeEnum.id, vehiclePassageTypeEnum);
        }
    }

    private Integer id;

    private String description;

    public static VehiclePassageTypeEnum toVehiclePassageTypeEnum(Integer id) {
        return Optional.ofNullable(map.get(id)).orElse(PASSAGE_TYPE_NOTHING);
    }

    public static VehiclePassageTypeEnum toVehiclePassageTypeEnumByKeTop(Integer id) {
        switch (id) {
            case 2:
                return EXIT;
            case 3:
                return MIDDLE_ENTRANCE;
            case 4:
                return MIDDLE_EXIT;
            default:
                return ENTRANCE;
        }
    }

}
